package org.raymond.icloud.apis.admin.service.fallbackFactory;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.raymond.icloud.apis.admin.service.ICommonServiceApi;
import org.raymond.icloud.apis.admin.vo.FakeCaptchaVO;
import org.raymond.icloud.common.core.model.Result;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ICommonServiceFallbackFactory implements FallbackFactory<ICommonServiceApi> {
    @Override
    public ICommonServiceApi create(Throwable throwable) {
        final String error = throwable.getMessage();
        log.error(error, throwable);
        return new ICommonServiceApi() {
            @Override
            public Result<String> publicKey() {
                return Result.error(error);
            }

            @Override
            public Result<FakeCaptchaVO> captcha(String mobile) {
                return Result.error(error);
            }
        };
    }
}
